/*  This file is part of LitSearch.

    LitSearch is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    LitSearch is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with LitSearch; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */

package de.fhbrs.litsearch;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
import java.util.regex.Pattern;

import org.apache.axis.types.NonNegativeInteger;

import com.softtech.jdbc.SQLResults;

import de.fhbrs.ConfigReader.ConfigReader;
import de.fhbrs.Logger.LogTypes;
import de.fhbrs.Logger.Logger;
import de.fhbrs.fedora.LitsearchFedoraConnection;
import de.fhbrs.sort.AuthorCompare;
import de.fhbrs.sort.Compare;
import de.fhbrs.sort.QuickSort;
import de.fhbrs.sort.TitleCompare;
import de.fhbrs.sort.TypeCompare;
import de.fhbrs.sort.YearCompare;
import fedora.server.types.gen.ComparisonOperator;
import fedora.server.types.gen.Condition;
import fedora.server.types.gen.FieldSearchResult;
import fedora.server.types.gen.ListSession;
import fedora.server.types.gen.ObjectFields;

/**
 * Parse search strings and query the database.
 *
 * @version 	1.2 17 Oct 2006
 * @author 	Christian Clever, Marco Werner
 * 
 */

public class SearchBean {
	
	private String searchWord;
	private String searchWordTitle;
	private String searchWordAuthor;
	private String searchWordSignatur;
	private String searchWordEditor;
	private String searchWordTitle2;
	private String searchWordInstitute;
	private String searchWordInventorynumber;
	
	private String searchWordPublisher;
	private String searchWordJournal;
	private String searchWordYear;
	private String searchWordMinYear;
	private String searchWordMaxYear;
	
	private String searchWordISBN;
	private String searchWordISSN;
	private String searchWordShelf;
	
	private String searchWideTitle;
	private String searchWideAuthor;
	private String searchWideSignatur;
	private String searchWideEditor;
	private String searchWideTitle2;
	private String searchWideInstitute;
	private String searchWideInventorynumber;
	
	private String searchWidePublisher;
	private String searchWideJournal;
	private String searchWideYear;
	private String searchWideMinYear;	
	private String searchWideMaxYear;
	
	private String searchWideISBN;
	private String searchWideISSN;
	private String searchWideShelf;
	
	private String checkboxArticle;
	private String checkboxBook;
	private String checkboxGreylit;

	private ArrayList searchArray;
	private String programmerInfo;
	private String searchResults;
	private String walletResults;
	private String errorMessage;
	private String searchMessage;
	private String view;
	private String orderBy;
	private int anzSearchResults;
	private int anzWalletResults;
	private int startwert;
	private int resultsPerPage;
	private int maximumHits;
	private int orderDirection;
	private LanguageBean langObject;
	private SettingsBean settingsObject;
	
	private UserBean userObject;
	private Vector wallet;
	//private Vector SearchWallet;
	private boolean extSearch;
	private boolean precise;
	
	private List<ObjectFields> objects;
	
	private boolean newSearchWord;
	
	private ObjectFields[] res;

	/** 
	 * Constructor sets initial values 
	 */
	public SearchBean(){
		
		this.objects = new Vector<ObjectFields>();
		
		this.searchWord="";
		this.searchWordTitle="";
		this.searchWordAuthor="";
		this.searchWordSignatur="";
		this.searchWordEditor="";
		this.searchWordTitle2="";
		this.searchWordInstitute="";
		this.searchWordInventorynumber="";
		
		this.searchWordPublisher="";
		this.searchWordJournal="";
		this.searchWordYear="";
		this.searchWordMinYear="";
		this.searchWordMaxYear="";
		
		this.searchWordISBN="";
		this.searchWordISSN="";
		this.searchWordShelf="";
		
		this.searchWideTitle="";
		this.searchWideAuthor="";
		this.searchWideSignatur="";
		this.searchWideEditor="";
		this.searchWideTitle2="";
		this.searchWideInstitute="";
		this.searchWideInventorynumber="";
		
		this.searchWidePublisher="";
		this.searchWideJournal="";
		this.searchWideYear="";
		this.searchWideMinYear="";	
		this.searchWideMaxYear="";
		
		this.searchWideISBN="";
		this.searchWideISSN="";
		this.searchWideShelf="";
		
		this.checkboxArticle="checked=\"checked\"";
		this.checkboxBook="checked=\"checked\"";
		this.checkboxGreylit="checked=\"checked\"";
		
		this.startwert=0;
		this.setPrecise(true);
		this.resultsPerPage=20;
		this.maximumHits=1000;
		this.programmerInfo="";
		this.orderBy="title1";
		this.orderDirection=0;
		this.wallet = new Vector();
		this.view="search";
		this.errorMessage="";
		this.setSearchMessage("");
		
		this.newSearchWord=true;
		this.res = null;
	
	}
	
	/** 
	 * Tells, if the current search is an extended search
	 * @return true if it is an extended search, false otherwise
	 */
	public boolean isExtSearch() {
		return extSearch;
	}
	
	public void setExtSearch(boolean extsearch) {
		if(this.isExtSearch() ^ extsearch ){
			this.resetSearch();
		}
		this.extSearch = extsearch;
	}
	
	/** 
	 * Set extsearch
	 * @param String extsearch
	 */
	public void setExtSearch(String extsearch) {
		if(extsearch!=null)
			this.setExtSearch(extsearch.equalsIgnoreCase("yes")?true:false);
	}
	
	/**
	 * Filters Search request and converts all Strings. Used in simple search.
	 * @param String x
	 * @return Array with all single SearchStrings
	 */
	public ArrayList doSearchWord(String x){
		x=x.trim();
		
		String searchWord = "";
		ArrayList searchWords = new ArrayList();
		boolean inWord = false;
		
		for (int i=0; i<x.length(); i++) {
			if (x.substring(i, i+1).equals("\"")) {
				if (!inWord) {
					inWord = true;
					if (!searchWord.trim().equals("")) {
						searchWords.add(searchWord.trim());
						searchWord = "";
					}
				}
				else {
					inWord = false;
					if (!searchWord.trim().equals("")) {
						searchWords.add(searchWord.trim());
						searchWord = "";
					}
				}
			}
			else {
				if (x.substring(i, i+1).equals(" ") && !inWord) {
					if (!searchWord.trim().equals("")) {
						searchWords.add(searchWord.trim());
						searchWord = "";
					}
				}
				else {
					searchWord += x.substring(i, i+1);
				}
			}
		}
		if (!searchWord.trim().equals("")) {
			searchWords.add(searchWord.trim());
		}
		return searchWords;
	}
	
	/** 
	 * Sets the SearchString
	 * @param String searchWord
	 */
	public void setSearchWord(String searchWord){
		if(searchWord!=null){
			if(!this.getSearchWord().equals(searchWord.trim())){
				this.setStartwert(0);
			}
			
			this.searchWord=searchWord.trim();
			if (!filter(searchWord).equals("")) {
				this.searchArray=this.doSearchWord(filter(searchWord));
			}
			else {
				this.searchWord = "";
			}
		}
	}
	
	/**
	 * Returns filtered string for security reasons
	 * @param String text
	 * @return filtered String  
	 */
	public String filter(String text) {
		if (text.replaceAll("\"","").length() == 0) {
			text = "";
		}
		int count = 0;
		for (int i=0; i<text.length(); i++) {
			if (text.substring(i,i+1).equals("\"")) {
				count++;
			}
		}
		if ((count % 2) == 1) {
			text = text.substring(0,text.lastIndexOf("\"")) + text.substring(text.lastIndexOf("\"") + 1);
		}
		text=replaceAll(text,"\\","");
		text=replaceAll(text,"'","\\'");
		text=replaceAll(text,";","\\;");
		text=replaceAll(text,"|","\\\\|");
		text=replaceAll(text,"*","\\\\*");
		text=replaceAll(text,"(","\\\\(");
		text=replaceAll(text,")","\\\\)");
		text=replaceAll(text,"[","\\\\[");
		text=replaceAll(text,"]","\\\\]");
		text=replaceAll(text,"{","\\\\{");
		text=replaceAll(text,"}","\\\\}");
		text=replaceAll(text,"?","\\\\?");
		text=replaceAll(text,"_","\\_");
		text=replaceAll(text,"%","\\%");
		text=replaceAll(text,"+","\\\\+");
		return text;
	}
	
	/**
	 * Returns filtered string for security reasons
	 * @param String text
	 * @return filtered String  
	 */
	public String filterFirst(String text){
		
		text=replaceAll(text,"\"","");
		return text;
	}
	/** 
	 * Gets the current searchString
	 * @return Search word as string
	 */
	public String getSearchWord(){
		return this.searchWord;	
	}
	
	/**
	 * Returns an filtered value from the current SearchWord  
	 * @return filterd SearchWord
	 */
	public String getSearchWordHtml(){
		
		String myReturn=this.searchWord;
		
		myReturn=this.replace(myReturn,"\"","&quot;");
		myReturn=this.replace(myReturn,"\"\"","");
		myReturn=this.replace(myReturn,"|","");
		
		return myReturn;	
	}
	/**
	 * Replaces substring in strings
	 * @param String. the whole String
	 * @param String search. Substring to replace
	 * @param String replace. Substringreplacement
	 * @return String with replaces ubstrings
	 */
	public String replace( String s, String search, String replace )
	{
		int start = 0, pos = 0;
		StringBuffer result = new StringBuffer( s.length() );
		while ( (pos = s.indexOf(search, start)) >= 0 )
		{
			result.append( s.substring(start, pos) );
			result.append( replace );
			start = pos + search.length();
		}
		result.append( s.substring(start) );
		
		return result.toString();
	}
	
	/** 
	 * returns the ResultTable for searched media 
	 * @return Searchresult String
	 */	
	public String getSearchResults(){
		if(this.searchResults==null)
			return "";
		else
			return this.searchResults;
	}
	
	/** 
	 * returns the ResultTable for media in the wallet
	 * @return walletcontent String
	 */		
	public String getWalletResults(){
		if(this.walletResults==null)
			return "";
		else
			return this.walletResults;
	}
	
	public void setSearchResults(String SearchResult){
		this.searchResults=SearchResult;
		
	}

	public void doSearch() throws Exception{
		
		Condition cons[] = null;
		List<Condition> searchObjects = new Vector<Condition>();

		//Fedora Connection Aufbau
		LitsearchFedoraConnection lfc = LitsearchFedoraConnection.getInstance();
		
		//Übergabe Suchfelder
		String[] resultFields = null;
		if(this.isExtSearch()){
			//Anhand der Suchwoerter muss der Suchstring gebaut werden
			String tmp[];
			ComparisonOperator cot;
			String wStar = "";
			String wQues = "";
			
			//Hauptachstitle
			if(this.getSearchWordTitle().compareTo("")!=0){
				if(this.getSearchWideTitle().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordTitle().split(" ");
				for(int i=0;i<tmp.length;i++){
					//System.out.println(tmp[i]);
					wStar = "";
					if(!tmp[i].startsWith("*")) wStar = "*";
					if(tmp[i].startsWith("?")) wStar = "";
					
					searchObjects.add(new Condition("title",cot,"title1="+wStar+tmp[i]));
				}
			}
			
			//Untertitel
			if(this.getSearchWordTitle2().compareTo("")!=0){
				if(this.getSearchWideTitle2().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordTitle2().split(" ");
				for(int i=0;i<tmp.length;i++){
					
					wStar = "";
					if(!tmp[i].startsWith("*")) wStar = "*";
					if(tmp[i].startsWith("?")) wStar = "";
					
					searchObjects.add(new Condition("title",cot,"title2="+wStar+tmp[i]));
				}
			}
			
			//Autor
			if(this.getSearchWordAuthor().compareTo("")!=0){
				if(this.getSearchWideAuthor().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordAuthor().split(" ");
				String search = "";
				for(int i=0;i<tmp.length;i++){
					search = tmp[i];
					if(!search.startsWith("?") && !search.startsWith("*")){
						search = "?"+search;
					}
					if(!search.endsWith("?") && !search.endsWith("*")){
						search = search+"?";
					}
					searchObjects.add(new Condition("creator",cot,search));

					//searchObjects.add(new Condition("creator",cot,"*" + tmp[i] + "*"));
				}
			}
			
			//Signatur
			if(this.getSearchWordSignatur().compareTo("")!=0){
				if(this.getSearchWideSignatur().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordSignatur().split(" ");
				for(int i=0;i<tmp.length;i++){
					
					wStar = "";
					if(!tmp[i].startsWith("*")) wStar = "*";
					if(tmp[i].startsWith("?")) wStar = "";
					
					searchObjects.add(new Condition("description",cot,"signatur="+wStar+tmp[i]));
				}
			}
			
			//Herausgeber
			if(this.getSearchWordEditor().compareTo("")!=0){
				if(this.getSearchWideEditor().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordEditor().split(" ");
				for(int i=0;i<tmp.length;i++){
					searchObjects.add(new Condition("contributor",cot,tmp[i]));
				}
			}
			
			//ISBN
			if(this.getSearchWordISBN().compareTo("")!=0){
				if(this.getSearchWideISBN().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordISBN().split(" ");
				for(int i=0;i<tmp.length;i++){
					
					wStar = "";
					if(!tmp[i].startsWith("*")) wStar = "*";
					if(tmp[i].startsWith("?")) wStar = "";
					
					searchObjects.add(new Condition("identifier",cot,"ISBN="+wStar+tmp[i]));
				}
			}
			
			//ISSN
			if(this.getSearchWordISSN().compareTo("")!=0){
				if(this.getSearchWideISSN().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordISSN().split(" ");
				for(int i=0;i<tmp.length;i++){
					
					wStar = "";
					if(!tmp[i].startsWith("*")) wStar = "*";
					if(tmp[i].startsWith("?")) wStar = "";
					
					searchObjects.add(new Condition("identifier",cot,"ISSN="+wStar+tmp[i]));
				}
			}
			
			//Institut
			if(this.getSearchWordInstitute().compareTo("")!=0){
				if(this.getSearchWideInstitute().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordInstitute().split(" ");
				for(int i=0;i<tmp.length;i++){
					
					wStar = "";
					if(!tmp[i].startsWith("*")) wStar = "*";
					if(tmp[i].startsWith("?")) wStar = "";
					
					searchObjects.add(new Condition("description",cot,"institute="+wStar+tmp[i]));
				}
			}
			
			//Verlag
			if(this.getSearchWordPublisher().compareTo("")!=0){
				if(this.getSearchWidePublisher().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordPublisher().split(" ");
				for(int i=0;i<tmp.length;i++){
					searchObjects.add(new Condition("publisher",cot,tmp[i]));
				}
			}
			
			//Journal/Zeitschrift
			if(this.getSearchWordJournal().compareTo("")!=0){
				if(this.getSearchWideJournal().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordJournal().split(" ");
				for(int i=0;i<tmp.length;i++){
					
					wStar = "";
					if(!tmp[i].startsWith("*")) wStar = "*";
					if(tmp[i].startsWith("?")) wStar = "";
					
					searchObjects.add(new Condition("description",cot,"journal="+wStar+tmp[i]));
				}
			}
			
			//Inventarnummer
			if(this.getSearchWordInventorynumber().compareTo("")!=0){
				if(this.getSearchWideInventorynumber().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordInventorynumber().split(" ");
				for(int i=0;i<tmp.length;i++){
					
					wStar = "";
					if(!tmp[i].startsWith("*")) wStar = "*";
					if(tmp[i].startsWith("?")) wStar = "";
					
					searchObjects.add(new Condition("description",cot,"inventorynumber="+wStar+tmp[i]));
				}
			}
			
			//Shelf
			if(this.getSearchWordShelf().compareTo("")!=0){
				if(this.getSearchWideShelf().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordShelf().split(" ");
				for(int i=0;i<tmp.length;i++){
					
					wStar = "";
					if(!tmp[i].startsWith("*")) wStar = "*";
					if(tmp[i].startsWith("?")) wStar = "";
					
					searchObjects.add(new Condition("description",cot,"shelf="+wStar+tmp[i]));
				}
			}

			//Jahr/Date
			if(this.getSearchWordYear().compareTo("")!=0){
				if(this.getSearchWideYear().compareTo("yes")==0){
					cot = ComparisonOperator.has;
				}else{
					cot = ComparisonOperator.eq;
				}
				//mehrere W�rter werden getrennt
				tmp = this.getSearchWordYear().split(" ");
				for(int i=0;i<tmp.length;i++){
					searchObjects.add(new Condition("date",cot,tmp[i]));
				}
			}
			
			/*
			//TODO Suche �ber Zeitraum nicht m�glich, da Operator mit YYYY-MM-DD Angabe arbeitet. Im DC ist YYYY
			//Jahr - Zeitraum
			if(this.getSearchWordMinYear().compareTo("")!=0){
				searchObjects.add(new Condition("date",ComparisonOperator.ge,this.getSearchWordMinYear()+"-01-01"));	
			}
			if(this.getSearchWordMaxYear().compareTo("")!=0){
				searchObjects.add(new Condition("date",ComparisonOperator.le,this.getSearchWordMaxYear()+"-01-01"));
			}
			*/
			
			cons = new Condition[searchObjects.size()];
			for(int i=0;i<searchObjects.size();i++){
				cons[i] = searchObjects.get(i);
			}
			
		}
		
		resultFields = new String[12];	
		resultFields[0] = "title";
		resultFields[1] = "pid";
		resultFields[2] = "date";
		resultFields[3] = "creator";
		resultFields[4] = "type";
		resultFields[5] = "description";
		resultFields[6] = "pid";
		resultFields[7] = "subject";
		resultFields[8] = "contributor";
		resultFields[9] = "identifier";
		resultFields[10] = "source";
		resultFields[11] = "coverage";
		
		
		String numResults = null;
		//Wieviele Ergebnisse angezeigt werden sollen
		try {
			Integer.parseInt(ConfigReader.getInstance().readKey("litsearch.global.search.results"));
		} catch (NumberFormatException ex){
			Logger.getInstance().log(LogTypes.ERROR, "Achtung Ihre config.xml Datei enthält für den Wert litsearch.global.searchresults Zahl. Es werden 100 Ergebnisse angezeigt.");
			numResults = "100";
		}
		
		if(numResults==null){
			numResults = ConfigReader.getInstance().readKey("litsearch.global.search.results");
		}		
		
		if(this.newSearchWord){
			//System.out.println("Neue Suche mit Wort:" + this.getSearchWord());
		
			NonNegativeInteger maxResults = new NonNegativeInteger(numResults);
			FieldSearchResult result = null;
			try {
				//APIA Methode wird angesprochen			
				result = lfc.findObj(resultFields, maxResults, this.getSearchWord(),cons);
				res = result.getResultList();
			} catch (Exception e){
				Logger.getInstance().log(LogTypes.ERROR, e.getMessage());
			}
		}
		
		this.newSearchWord = true;
		
		if(res == null || res.length==0){
			this.resetSearch();
			this.setErrorMessage(langObject.getTextFor("search.noResults"));
			return;
		}
		
		List<ObjectFields> fedoraResults = new Vector<ObjectFields>();
		
		for (int i=0; i<res.length;i++) {
			if(!res[i].getPid().startsWith("lit:")){
				Logger.getInstance().log(LogTypes.WARNING, "Achtung das Fedora Object mit der PID " + res[i].getPid() + " wird bei der Ausgabe der Suche ignoriert!");
			} else {
				fedoraResults.add(res[i]);
			}
		}
		
		res = null;
		res = new ObjectFields[fedoraResults.size()];
		
		for(int i = 0; i<fedoraResults.size();i++){
			res[i] = fedoraResults.get(i);
		}
		
		fedoraResults.clear();
		fedoraResults = null;
		
		if(res == null || res.length==0){
			this.resetSearch();
			this.setErrorMessage(langObject.getTextFor("search.noResults"));
			return;
		}
		
		//Sortierung der Ergebnisse
		if(this.getOrderBy().compareTo("title1")==0) {
			Compare compare = new TitleCompare();
			QuickSort.sort(res, compare);
			if(this.getOrderDirection()==1)
				orderByDesc(res);
		} else if(this.getOrderBy().compareTo("litart")==0) {
			Compare compare = new TypeCompare();
			QuickSort.sort(res, compare);
			if(this.getOrderDirection()==1)
				orderByDesc(res);
		} else if(this.getOrderBy().compareTo("author")==0) {
			Compare compare = new AuthorCompare();
			QuickSort.sort(res, compare);
			if(this.getOrderDirection()==1)
				orderByDesc(res);
		} else if(this.getOrderBy().compareTo("year")==0) {
			Compare compare = new YearCompare();
			QuickSort.sort(res, compare);
			if(this.getOrderDirection()==1)
				orderByDesc(res);
		}
		
		
		//Auswertung der ausgewählten Typen von Literatur
		//Wurden alle Typen von Literatur aus gewählt ??
		//Wurden nur einzelne ausgewählt wie z.B. 
		//Graue Literatur oder Buch oder Artikel
		boolean greylit = false;
		boolean book = false;
		boolean artikel = false;
		
		//Je nachdem welcher Wert gesetzt wurde wird die zuvor
		//definierte Variable auf true gesetzt.
		if(this.getCheckboxGreylit().compareTo("checked=\"checked\"")==0)
			greylit=true;
		if(this.getCheckboxArticle().compareTo("checked=\"checked\"")==0)
			artikel=true;
		if(this.getCheckboxBook().compareTo("checked=\"checked\"")==0)
			book=true;
		
		//Untersuche alle Suchergebnisse ob sie entsprechend der ausgewählten
		//Literatur Typen entsprechen. 
		//Falls ein Ergebnis nicht zu einem ausgewählten Typ passen sollte wird
		//dieser in der Liste nicht angefügt.
		
		//Bsp. Ich suche nach weather möchte aber nur Graue Literatur berücksichtigen.
		//Die Variable greylit ist true die beiden anderen Variablen 
		//artikel und book sind dementsprechend false.
		//Falls nun ein Suchergebnis (einzelnes Element) vom Typ graue literatur ist,
		//und greylit auf true gesetzt ist, dann wird das Ergebnis in der Liste
		//angehängt...
		
		objects.clear();

		for (int i=0; i<res.length;i++) {
			try{
				String type = res[i].getType(0);
				
				if(type.compareTo("greylit")==0 && greylit) {
					objects.add(res[i]);
				} else if(type.compareTo("book")==0 && book) {
					objects.add(res[i]);
				} else if(type.compareTo("artikel")==0 && artikel) {
					objects.add(res[i]);
				}
				//i++;
			}catch(java.lang.NullPointerException e){
				System.out.println("SearchBean: "+i);
			}
			
		}
		
		if(objects == null || objects.size()==0){
			this.resetSearch();
			this.setErrorMessage(langObject.getTextFor("search.noResults"));
			return;
		}

	}
	
	/** 
	 * Gets the Result for the search (SearchWord) from the database and writes it to var searchResults
	 */	
	public void getMedia() throws Exception {
		if(this.getSearchWord()==null || this.getSearchWord().equalsIgnoreCase("") && !this.isExtSearch())
			return;
		
		if(isExtSearch() && this.getSearchWordAuthor().equals("") && this.getSearchWordTitle().equals("") && this.getSearchWordSignatur().equals("") && this.getSearchWordEditor().equals("") && this.getSearchWordISBN().equals("") && this.getSearchWordISSN().equals("") && this.getSearchWordTitle2().equals("") && this.getSearchWordInstitute().equals("") && this.getSearchWordPublisher().equals("") && this.getSearchWordJournal().equals("") && this.getSearchWordYear().equals("") && this.getSearchWordMinYear().equals("") && this.getSearchWordMaxYear().equals("") && this.getSearchWordInventorynumber().equals("") && this.getSearchWordShelf().equals("")) {
			this.resetSearch();
			return;
		}
		
		this.startwert = 0;
		this.objects.clear();
		
		String year;
		String rowClass;
		String icon;
		String myTable="";
		String litart="";

		this.doSearch();
		
		//Ab hier bezieht sich nun alles auf die Liste und nicht mehr das Array!!!
		//Seitenaufteilung
		
		this.setAnzSearchResults(objects.size());
		
		for (int row=0;row<minimum(this.resultsPerPage+this.startwert,this.anzSearchResults);row++){
			
			int myCounter=row+1;
			if(row%2==0)
				rowClass="lightgrey";
			else
				rowClass="dargrey";
		
			litart = "";
			
			if (objects.get(row).getType(0).equals("book")) litart = "Buch";
			if (objects.get(row).getType(0).equals("artikel")) litart = "Artikel";
			if (objects.get(row).getType(0).equals("greylit")) litart = "Graue Literatur";
			icon="<img src=\"images/"+objects.get(row).getType(0)+".png\"  alt=\""+litart+"\" title=\""+litart+"\" />";
			
			if(objects.get(row).getDate(0).equalsIgnoreCase(""))
				year="n.a.";
			else
				year=objects.get(row).getDate(0);
			String id_str = objects.get(row).getPid();
				int id = Integer.parseInt(id_str.substring(4));
			myTable += "<tr class=\""+rowClass+"\">";	
			myTable += "<td style=\"vertical-align:top; width:27px;\"><a name=\"record"+id+"\" class=\"nolink\">"+myCounter+"</a></td>";
			myTable += "<td style=\"vertical-align:top; width:27px;\">"+this.checkWalletId(id)+"</td>";
			myTable += "<td style=\"vertical-align:top; width:47px;\">"+icon+"</td>";		
			myTable += "<td style=\"vertical-align:top;\">"+this.showAuthorArray(this.convertToArray(objects.get(row).getCreator(0)))+"</td>";
			myTable += "<td style=\"vertical-align:top;\"><a href=\"index.jsp?content=details&amp;id="+id+"\">"+objects.get(row).getTitle(0).substring(7)+"</a></td>";
			myTable += "<td style=\"vertical-align:top; text-align:right\">"+year+"</td>";
			myTable += "</tr>";
		}
		this.searchResults=myTable;
	}
	
	private void orderByDesc(ObjectFields[] res){
		ObjectFields[] tmp = new ObjectFields[res.length];
		for(int i=0;i<res.length;i++){
			tmp[i] = res[i];
		}
		int a = 0;
		for(int i =res.length-1;i>=0;i--){
			res[a] = tmp[i];
			a++;
		}
	}
	
	
	/** 
	 * Gets the Result for the search (SearchWord) from the database and writes it to var searchResults
	 */	
	public void getMedia(int startwert) throws Exception {
		if(this.getSearchWord()==null || this.getSearchWord().equalsIgnoreCase("") && !this.isExtSearch())
			return;
		
		if(isExtSearch() && this.getSearchWordAuthor().equals("") && this.getSearchWordTitle().equals("") && this.getSearchWordSignatur().equals("") && this.getSearchWordEditor().equals("") && this.getSearchWordISBN().equals("") && this.getSearchWordISSN().equals("") && this.getSearchWordTitle2().equals("") && this.getSearchWordInstitute().equals("") && this.getSearchWordPublisher().equals("") && this.getSearchWordJournal().equals("") && this.getSearchWordYear().equals("") && this.getSearchWordMinYear().equals("") && this.getSearchWordMaxYear().equals("") && this.getSearchWordInventorynumber().equals("") && this.getSearchWordShelf().equals("")) {
			this.resetSearch();
			return;
		}		
		
		String year;
		String rowClass;
		String icon;
		String myTable="";
		String litart="";
		
		if(objects.size()==0){
			this.searchResults="";
			//throw new Exception(langObject.getTextFor("search.noResults"));
			this.setErrorMessage(langObject.getTextFor("search.noResults"));
			return;
		}
		
		if(objects.size()<startwert){
			this.searchResults="";
			//throw new Exception(langObject.getTextFor("search.noResults"));
			this.setErrorMessage(langObject.getTextFor("search.noResults"));
			return;
		}
		
		//Ab hier bezieht sich nun alles auf die Liste und nicht mehr das Array!!!
		//Seitenaufteilung
		//this.setAnzSearchResults(objects.size()+this.startwert);
		
		for (int row=startwert;row<minimum(this.startwert+this.resultsPerPage,this.anzSearchResults);row++){
			
			int myCounter=row+1;
			if(row%2==0)
				rowClass="lightgrey";
			else
				rowClass="darkgrey";
			
			litart = "";
		
			if (objects.get(row).getType(0).equals("book")) litart = "Buch";
			if (objects.get(row).getType(0).equals("artikel")) litart = "Artikel";
			if (objects.get(row).getType(0).equals("greylit")) litart = "Graue Literatur";
			icon="<img src=\"images/"+objects.get(row).getType(0)+".png\"  alt=\""+litart+"\" title=\""+litart+"\" />";
			
			if(objects.get(row).getDate(0).equalsIgnoreCase(""))
				year="n.a.";
			else
				year=objects.get(row).getDate(0);
			String id_str = objects.get(row).getPid();
			int id = Integer.parseInt(id_str.substring(4));
			myTable += "<tr class=\""+rowClass+"\">";	
			myTable += "<td style=\"vertical-align:top; width:27px;\"><a name=\"record"+id+"\" class=\"nolink\">"+myCounter+"</a></td>";
			myTable += "<td style=\"vertical-align:top; width:27px;\">"+this.checkWalletId(id)+"</td>";
			myTable += "<td style=\"vertical-align:top; width:47px;\">"+icon+"</td>";		
			myTable += "<td style=\"vertical-align:top;\">"+this.showAuthorArray(this.convertToArray(objects.get(row).getCreator(0)))+"</td>";
			myTable += "<td style=\"vertical-align:top;\"><a href=\"index.jsp?content=details&amp;id="+id+"\">"+objects.get(row).getTitle(0).substring(7)+"</a></td>";
			myTable += "<td style=\"vertical-align:top; text-align:right\">"+year+"</td>";
			myTable += "</tr>";
		}
		
		this.searchResults=myTable;
	}
	
	/** 
	 * Gets the Result for the search (SearchWord) from the database and writes it to var walletResults
	 */	
	public void getWalletMedia()throws Exception{
		String year;
		String rowClass;
		String icon;
		String myTable="";
		String litart="";
		
		if(this.getWallet().isEmpty()){
			this.walletResults="";
			throw new Exception(langObject.getTextFor("search.noResults"));
		}

		MediumBean tmp = new MediumBean();
		tmp.setSortWallet(this.getOrderBy());
		
		this.setAnzWalletResults(this.walletSize());
		

		Vector<MediumBean> walletElements = new Vector<MediumBean>();
		
		for (int row=0; row < this.getAnzWalletResults(); row++){
			tmp.initializeMedium(this.wallet.get(row).toString());
			tmp.setSortWallet(this.getOrderBy());
			walletElements.add(tmp);
			tmp = new MediumBean();
		}
		
		Collections.sort(walletElements);
		int row = 0;
		int max = 0;
		int inc = 0;
		int i = 0;
		
		switch(this.orderDirection){
			case 0:	//asc
				row = 0;
				i = 0;
				max = walletElements.size();
				inc = 1;
				break;
			case 1: //desc
				row = walletElements.size()-1;
				i = -walletElements.size();
				max = 0;
				inc = -1;
				break;
			default:
				row = 0;
				i = 0;
				max = walletElements.size();
				inc = 1;
		}
		
		for (; i < max; i++,row=row+inc){
			//System.out.println("ROW: "+row+" I: "+i+" SORT: "+this.orderDirection);
			//System.out.println("ID: "+this.wallet.get(row).toString());
			tmp = walletElements.get(row);
			
			int myCounter=row+1;
			if(row%2==0)
				rowClass="lightgrey";
			else
				rowClass="darkgrey";
			
			litart = "";
			if (tmp.getLitartSimple().equals("book")) litart = "Buch";
			if (tmp.getLitartSimple().equals("artikel")) litart = "Artikel";
			if (tmp.getLitartSimple().equals("greylit")) litart = "Graue Literatur";
			icon="<img src=\"images/"+tmp.getLitartSimple()+".png\" alt=\""+litart+"\" title=\""+litart+"\" />";
			
			if(tmp.getYearPrint().equalsIgnoreCase(""))
				year="n.a.";
			else
				year=tmp.getYearPrint();
			
			myTable += "<tr class=\""+rowClass+"\">";	
			myTable += "<td style=\"vertical-align:top; width:27px;\">"+myCounter+"</td>";
			//System.out.println(Integer.parseInt((tmp.getPid().split(":"))[1]));
			myTable += "<td style=\"vertical-align:top; width:27px;\">"+this.checkWalletId(Integer.parseInt((tmp.getPid().split(":"))[1]))+"</td>";
			myTable += "<td style=\"vertical-align:top; width:47px;\">"+icon+"</td>";		
			myTable += "<td style=\"vertical-align:top;\">"+tmp.getAuthorsPrint()+"</td>";
			myTable += "<td style=\"vertical-align:top;\"><a href=\"index.jsp?content=details&amp;id="+Integer.parseInt((tmp.getPid().split(":"))[1])+"\">"+tmp.getTitle1Print()+"</a></td>";
			myTable += "<td style=\"vertical-align:top; text-align:right\">"+year+"</td>";
			myTable += "</tr>";
			
			//System.out.println(myTable);
		}
		
		this.walletResults=myTable;
		
	}
	
	/** 
	 * Get Information about the current search
	 * @return Result info as string
	 */
	public String getResultInfo() {	
		int von = startwert+1;
		int bis = minimum((von + this.resultsPerPage-1),this.anzSearchResults);
		
		String myString="";
		myString+=this.langObject.getTextFor("search.Shown")+": "+von+" - "+bis+" von "+this.anzSearchResults;
		
		if(this.maximumHits==this.anzSearchResults || this.anzSearchResults==0)
			return "";
		else		
			return myString;
	}	
	
	/** 
	 * Get the Search Navigation Bar (go directly to the differen pages)
	 * @return Page navigation as HTML string
	 */
	public String getPageNavi() {	
		int showPages =19;
		
		int pages =(int)(double)java.lang.Math.ceil((double)this.anzSearchResults/(double)this.resultsPerPage);
		
		if(pages==1)
			return "";
		String myString=this.langObject.getTextFor("search.Pages")+": ";
		
		int aktuelleSeite=this.startwert/this.resultsPerPage;
		int[] range=getRange(aktuelleSeite,pages,minimum(showPages,pages));
		
		for(int i=range[0];i<=range[1];i++){
			String startBold;
			String endBold;
			int startAt=(i-1)*this.resultsPerPage;
			
			if((i-1)*this.resultsPerPage==this.startwert){
				startBold="<b>";
				endBold="</b>";
			}else{
				startBold="";
				endBold="";
			}
			myString+="<a href=\"index.jsp?content=search&amp;startwert="+startAt+"\">"+startBold+i+endBold+"</a> ";	
		}
		
		if(this.maximumHits==this.anzSearchResults || this.anzSearchResults==0)
			return "";
		else
			return myString;
	}
	
	/** 
	 * Get the previous Button
	 * @return HTML link for previous page
	 */
	public String getPrevNavi() {	
		int pages =(int)java.lang.Math.ceil(this.anzSearchResults/this.resultsPerPage);
		if(pages * this.resultsPerPage<this.anzSearchResults)
			pages+=1;
		String LinkName=this.langObject.getTextFor("search.Previous");
		
		
		int previousStart=this.startwert-this.resultsPerPage;
		String myString="<a href=\"index.jsp?content="+this.getView()+"&amp;startwert="+previousStart+"\"> "+LinkName+" </a> ";
		
		
		if(this.maximumHits==this.anzSearchResults || this.anzSearchResults==0 ){
			return "";
		}else{
			if(previousStart<0)
				return LinkName;
			else
				return myString;
		}
	}	
	
	/** 
	 * Get the Next Button
	 * @return HTML link for next page
	 */
	public String getNextNavi() {	
		int pages =(int)java.lang.Math.ceil(this.anzSearchResults/this.resultsPerPage);
		if(pages * this.resultsPerPage<this.anzSearchResults)
			pages+=1;
		
		String LinkName=this.langObject.getTextFor("search.Next");//
		
		int NextStart=this.startwert+this.resultsPerPage;
		String myString="<a href=\"index.jsp?content="+this.getView()+"&amp;startwert="+NextStart+"\"> "+LinkName+" </a> ";
		
		
		if(this.maximumHits==this.anzSearchResults || this.anzSearchResults==0 ){
			return "";
		}else{
			if(NextStart>=pages*this.resultsPerPage)
				return LinkName;
			else
				return myString;
		}
	}	
	
	/** 
	 * Get the minimum of 2 values
	 * @param int one
	 * @param int two
	 * @return Minimum of the two supplied values
	 */
	public int minimum(int eins,int zwei){
		if(eins>zwei)
			return zwei;
		else
			return eins;
	}
	
	/** 
	 * Get an array of 2 Integers. The first one is the first show page in the page Navigation, the second is the last one.
	 * @param Integer actual position 
	 * @param Integer number of pages
	 * @param Integer numer of maximum links in the page Navogation
	 */	
	public int[] getRange(int pos, int pages,int toShow){
		
		int[] myArray= new int[2];
		
		if(pos-toShow/2<=0){
			
			myArray[0]=1;
			myArray[1]=minimum(toShow,pages);	
			
			this.programmerInfo="Fall1";
			
		}else if(pos+toShow/2>=pages){
			
			myArray[0]=pages-toShow+1;
			myArray[1]=pages;
			
			this.programmerInfo="Fall2";
		}else{
			
			myArray[0]=pos-toShow/2+1;
			myArray[1]=pos+toShow/2+1;
			
			this.programmerInfo="Fall3";
		}
		
		return myArray;
		
	}
	
	/** 
	 * Get the maximum of 2 values
	 * @param Integer one
	 * @param Integer two
	 */	
	public int maximum(int eins,int zwei){
		if(eins>=zwei)
			return eins;
		else
			return zwei;
	}	
	
	/** 
	 * Gets the Number of results for the current search
	 */	
	public int getAnzSearchResults() {
		return anzSearchResults;
	}
	
	/** 
	 * Sets the Number of results for the current search
	 * @param anzSearchResults
	 */
	public void setAnzSearchResults(int anzSearchResults) {
		this.anzSearchResults = anzSearchResults;
	}
	
	/** 
	 * Gets the startwert
	 */
	public int getStartwert() {
		return startwert;
	}
	
	/** 
	 * Sets the startwert
	 * @param startwert
	 */
	public void setStartwert(int startwert) {
		
		this.startwert = startwert;
	}
	
	/** 
	 * Sets the startwert.
	 * @param  startwert
	 */
	public void setStartwert(String startwert) {
		try{
			this.startwert = Integer.parseInt(startwert);
		}catch(Exception e){}
	}
	
	/** 
	 * Help method for the programmer...return the content of "programmersInfo"
	 */
	public String getProgrammerInfo() {
		
		return this.programmerInfo;
	}
	
	/** 
	 * Help method for the programmer...set "programmersInfo"
	 * @param  progammerMeldung
	 */
	public void setProgrammerInfo(String progammerMeldung) {
		this.programmerInfo = progammerMeldung;
	}
	
	/** 
	 * gets the order vaklue of the search 
	 */
	public String getOrderBy() {
		return orderBy;
	}
	
	/** 
	 * Sets the order value for the current search
	 * @param  orderBy
	 */
	public void setOrderBy(String orderBy){

		if(orderBy != null)
			this.orderBy = orderBy;

	}
	
	/** 
	 * Gets the Order Direction
	 */
	public int getOrderDirection() {
		return orderDirection;
	}
	
	/** 
	 * Gets the Order Direction Image
	 */
	public String getOrderDirectionIcon(String field) {
		
		if(this.orderDirection==0 && this.orderBy.equals(field))
			return "<img src=\"images/ascending.gif\" alt=\"ascending\" />";
		else if(this.orderDirection==1 && this.orderBy.equals(field))
			return "<img src=\"images/descending.gif\" alt=\"descending\" />";
		else
			return "";
	}
	
	/** 
	 * Gets the opposite Order Direction
	 */
	public int getOppositeOrderDirection() {
		
		return (orderDirection+1)%2;
	}
	/** 
	 * Sets the order Direction (1 or 0)
	 * @param orderDirection
	 */
	public void setOrderDirection(String orderDirection){
		
		if(orderDirection == null)
			return;
		
		if(orderDirection != null && (orderDirection.equals("1") || orderDirection.equals("0"))){
			try{
				this.orderDirection = Integer.parseInt(orderDirection);
				this.newSearchWord = false;
			}catch(Exception e){
				this.setErrorMessage("orderby must be an integer and 1 or 0");
			}
		}else{
			this.orderDirection = 0;
			this.setErrorMessage("orderby must be 1 or 0");
			this.newSearchWord = false;
		}
		
		
		
	}
	
	/** 
	 * Sets the order Direction
	 * @param orderDirection
	 */
	public void setOrderDirection(int orderDirection){
		this.orderDirection = orderDirection;	
		
	}
	
	/** 
	 * Returns an array of all search words
	 * @return Array with single search words
	 */
	public ArrayList getSearchArray() {
		return searchArray;
	}
	
	
	/** 
	 * Returns the "where"-Part on a SQL String. Build up on searchwords. Used in "simple Search"
	 * @return SQL String
	 */
	public String getSqlSearch()throws Exception {
		
		String wider="";
		if(this.isPrecise())
			wider="";
		
		String sqlTitle1="";
		String sqlAuthor="";
		String sqlSignatur="";
		String sqlEditor="";
		String sqlTitle2="";
		String sqlInstitute="";
		String sqlPublisher="";
		String sqlJournal="";
		String sqlISBN="";
		String sqlISSN="";
		
		ArrayList array=this.getSearchArray();

		int i=0;
		String not="";
		String suchwort;
		while(i<array.size()){
			not="";
			suchwort= (String)array.get(i);
			suchwort=this.replace(suchwort,"ä","(ä|ae)");
			suchwort=this.replace(suchwort,"Ä","(Ä|AE)");
			suchwort=this.replace(suchwort,"ö","(ö|oe)");
			suchwort=this.replace(suchwort,"Ö","(Ö|OE)");
			suchwort=this.replace(suchwort,"ü","(ü|ue)");
			suchwort=this.replace(suchwort,"Ü","(Ü|UE)");
			suchwort=this.replace(suchwort,"ß","(ß|ss)");
			
						
			
			if(suchwort.substring(0,1).equals("-")){
				not="not";
				suchwort=suchwort.substring(1,suchwort.length());
			}
			sqlTitle1+="title1 "+not+" rlike '"+wider+suchwort+wider+"' or ";
			sqlAuthor+="author "+not+" rlike '"+wider+suchwort+wider+"' or ";
			sqlSignatur+="signatur "+not+" rlike '"+wider+suchwort+wider+"' or ";
			sqlEditor+="editor "+not+" rlike '"+wider+suchwort+wider+"' or ";
			sqlTitle2+="title2 "+not+" rlike '"+wider+suchwort+wider+"' or ";
			sqlInstitute+="institute "+not+" rlike '"+wider+suchwort+wider+"' or ";
			sqlPublisher+="publisher "+not+" rlike '"+wider+suchwort+wider+"' or ";
			sqlPublisher+="inventorynumber "+not+" rlike '"+wider+suchwort+wider+"' or ";
			sqlJournal+="journal "+not+" rlike '"+wider+suchwort+wider+"' or ";
			sqlISBN+="isbn "+not+" rlike '"+wider+suchwort+wider+"' or replace(isbn,'-','') "+not+" rlike '"+wider+suchwort.replaceAll("-","")+wider+"' or ";
			sqlISSN+="issn "+not+" rlike '"+wider+suchwort+wider+"' or replace(issn,'-','') "+not+" rlike '"+wider+suchwort.replaceAll("-","")+wider+"' or ";
			i++;
		}
		
		int shortMeBy=4;
		sqlTitle1=sqlTitle1.substring(0,sqlTitle1.length()-shortMeBy);
		sqlAuthor=sqlAuthor.substring(0,sqlAuthor.length()-shortMeBy);
		sqlSignatur=sqlSignatur.substring(0,sqlSignatur.length()-shortMeBy);
		sqlEditor=sqlEditor.substring(0,sqlEditor.length()-shortMeBy);
		sqlTitle2=sqlTitle2.substring(0,sqlTitle2.length()-shortMeBy);
		sqlInstitute=sqlInstitute.substring(0,sqlInstitute.length()-shortMeBy);
		sqlPublisher=sqlPublisher.substring(0,sqlPublisher.length()-shortMeBy);
		sqlJournal=sqlJournal.substring(0,sqlJournal.length()-shortMeBy);
		sqlISBN=sqlISBN.substring(0,sqlISBN.length()-shortMeBy);
		sqlISSN=sqlISSN.substring(0,sqlISSN.length()-shortMeBy);
		
		String myReturn="("+sqlTitle1+ " or "+sqlAuthor+" or "+sqlSignatur+" or "+sqlEditor+" or "+sqlTitle2+" or "+sqlInstitute+" or "+sqlPublisher+" or "+sqlJournal+" or "+sqlISBN+" or "+sqlISSN+") and released=true and deleted=0";
		
		if (!this.getCheckboxArticle().equals("") || !this.getCheckboxBook().equals("") || !this.getCheckboxGreylit().equals("")) {
			String myReturnAddon = " and (";
			if (!this.getCheckboxArticle().equals("")) myReturnAddon += "litart='artikel'";
			if (!this.getCheckboxBook().equals("")) {
				if (myReturnAddon.length() > 6) myReturnAddon += " or ";
				myReturnAddon += "litart='book'";
			}
			if (!this.getCheckboxGreylit().equals("")) {
				if (myReturnAddon.length() > 6) myReturnAddon += " or ";
				myReturnAddon += "litart='greylit'";
			}
			myReturnAddon += ")";
			myReturn += myReturnAddon;
		}
		else {
			myReturn += " and (litart='')";
		}
		//System.out.println("\nStandardSearch:\n"+myReturn+"\n");
		
		return myReturn;
	}
	
	/** 
	 * Returns the "where"-Part on a SQL String. Build up on searchwords. Used in "Extended Search"
	 * @return SQL String
	 */
	public String getSqlExtSearch() throws Exception {
		String myReturn="";
		String title=filter(this.getSearchWordTitle());
		String author=filter(this.getSearchWordAuthor());
		String signatur=filter(this.getSearchWordSignatur());
		String editor=filter(this.getSearchWordEditor());
		String isbn=filter(this.getSearchWordISBN());
		String issn=filter(this.getSearchWordISSN());
		String title2=filter(this.getSearchWordTitle2());
		String institute=filter(this.getSearchWordInstitute());
		String inventorynumber=filter(this.getSearchWordInventorynumber());
		String shelf=filter(this.getSearchWordShelf());
		String publisher=filter(this.getSearchWordPublisher());
		String journal=filter(this.getSearchWordJournal());
		String year=filter(this.getSearchWordYear());
		String MinYear=filter(this.getSearchWordMinYear());
		String MaxYear=filter(this.getSearchWordMaxYear());
		
		
		
		title=this.replace(title,"ä","(ä|ae)");
		title=this.replace(title,"Ä","(Ä|AE)");
		title=this.replace(title,"ö","(ö|oe)");
		title=this.replace(title,"Ö","(Ö|OE)");
		title=this.replace(title,"ü","(ü|ue)");
		title=this.replace(title,"Ü","(Ü|UE)");
		title=this.replace(title,"ß","(ß|ss)");
		
		author=this.replace(author,"ä","(ä|ae)");
		author=this.replace(author,"Ä","(Ä|AE)");
		author=this.replace(author,"ö","(ö|oe)");
		author=this.replace(author,"Ö","(Ö|OE)");
		author=this.replace(author,"ü","(ü|ue)");
		author=this.replace(author,"Ü","(Ü|UE)");
		author=this.replace(author,"ß","(ß|ss)");
				
		
		if(this.getSearchWideTitle().equals("no")){
			title="(^| |,|;|\\\\.)"+title+"( |\\\\.|!| |,|;|$)";
		}
		
		if(this.getSearchWideAuthor().equals("no"))
			author="(^\\\"| |,)"+author+"( |,|\\\"$)";
		
		if(this.getSearchWideInventorynumber().equals("no"))
			inventorynumber="(^| |,)"+inventorynumber+"( |,|$)";
		
		if(this.getSearchWideShelf().equals("no"))
	           shelf="(^| |,)"+shelf+"( |,|$)";
			
		if(this.getSearchWideSignatur().equals("no"))
	           signatur="(^| |,)"+signatur+"( |,|$)";
	       
	       
	       if(this.getSearchWideEditor().equals("no"))
	           editor="(^| |,)"+editor+"( |,|$)";
	       if(this.getSearchWideISBN().equals("no"))
	           isbn="(^| |,)"+isbn+"( |,|$)";
	       if(this.getSearchWideISSN().equals("no"))
	           issn="(^| |,)"+issn+"( |,|$)";
	       if(this.getSearchWideTitle2().equals("no"))
	           title2="(^| |,)"+title2+"( |,|$)";
	       if(this.getSearchWideInstitute().equals("no"))
	           institute="(^| |,)"+institute+"( |,|$)";
	       if(this.getSearchWidePublisher().equals("no"))
	           publisher="(^| |,)"+publisher+"( |,|$)";
	       if(this.getSearchWideJournal().equals("no"))
	           journal="(^| |,)"+journal+"( |,|$)";
	       if(this.getSearchWideYear().equals("no"))
	           year="(^| |,)"+year+"( |,|$)";
	       if(this.getSearchWideMinYear().equals("no"))
	           MinYear="(^| |,)"+MinYear+"( |,|$)";
	       if(this.getSearchWideMaxYear().equals("no"))
	           MaxYear="(^| |,)"+MaxYear+"( |,|$)";
				
		
		if(!title.equals(""))
			myReturn+="title1 rlike '"+title+"' and ";
		if(!author.equals(""))
			myReturn+="author rlike '"+author+"' and ";
		if(!signatur.equals(""))
			myReturn+="signatur rlike '"+signatur+"' and ";
		if(!editor.equals(""))
			myReturn+="editor rlike '"+editor+"' and ";
		if(!isbn.equals(""))
			myReturn+="replace(isbn,'-','') rlike '"+isbn.replaceAll("-","")+"' and ";
		if(!issn.equals(""))
			myReturn+="replace(issn,'-','') rlike '"+issn.replaceAll("-","")+"' and ";
		if(!title2.equals(""))
			myReturn+="title2 rlike '"+title2+"' and ";
		if(!institute.equals(""))
			myReturn+="institute rlike '"+institute+"' and ";
		if(!inventorynumber.equals(""))
			myReturn+="inventorynumber rlike '"+inventorynumber+"' and ";
		if(!shelf.equals(""))
			myReturn+="shelf rlike '"+shelf+"' and ";
		if(!publisher.equals(""))
			myReturn+="publisher rlike '"+publisher+"' and ";
		if(!journal.equals(""))
			myReturn+="journal rlike '"+journal+"' and ";
		if(!year.equals(""))
			myReturn+="year = '"+year+"' and ";
		if(!MinYear.equals(""))
			myReturn+="year >= '"+MinYear+"' and ";
		if(!MaxYear.equals(""))
			myReturn+="year <= '"+MaxYear+"' and ";
	
		myReturn=myReturn.substring(0,myReturn.length()-5);
		myReturn="("+myReturn+")"+" and released=true and deleted=0";
		
		if (!this.getCheckboxArticle().equals("") || !this.getCheckboxBook().equals("") || !this.getCheckboxGreylit().equals("")) {
			String myReturnAddon = " and (";
			if (!this.getCheckboxArticle().equals("")) myReturnAddon += "litart='artikel'";
			if (!this.getCheckboxBook().equals("")) {
				if (myReturnAddon.length() > 6) myReturnAddon += " or ";
				myReturnAddon += "litart='book'";
			}
			if (!this.getCheckboxGreylit().equals("")) {
				if (myReturnAddon.length() > 6) myReturnAddon += " or ";
				myReturnAddon += "litart='greylit'";
			}
			myReturnAddon += ")";
			myReturn += myReturnAddon;
		}
		else {
			myReturn += " and (litart='')";
		}
		
		//System.out.println("\nExtSearch:\n"+myReturn+"\n");
		return myReturn;
	}
	
	public void setLanguage(LanguageBean object){
		this.langObject=object;
	}
	
	/** 
	 * Returns The current Language
	 * @return Language
	 */
	public String getLanguage(){
		return this.langObject.getLanguage();//TextFor("search.thereWere");
	}
	
	/** 
	 * Returns an integer wich indicates the maximum hits a query may return.
	 * @return Integer maximumHits
	 */
	public int getMaximumHits() {
		return maximumHits;
	}
	
	
	public LanguageBean getLangObject() {
		return langObject;
	}
	
	public void setLangObject(LanguageBean langObject) {
		this.langObject = langObject;
	}
	
	/** 
	 * Returns an integer wich indicates how many results are show on a single page.
	 * @return Integer maximumHits
	 */
	public int getResultsPerPage() {
		return resultsPerPage;
	}
	
	/** 
	 * sets an integer wich indicates how many results are show on a single page.
	 * @param Integer resultsPerPage
	 */
	public void setResultsPerPage(int resultsPerPage) {
		this.resultsPerPage = resultsPerPage;
	}
	
	/** 
	 * sets an integer wich indicates the maximum hist, an query may return.
	 * @parameter Integer maximumHits
	 */
	public void setMaximumHits(int maximumHits) {
		this.maximumHits = maximumHits;
	}
	
	
	public UserBean getUserObject() {
		return userObject;
	}
	
	public void setUserObject(UserBean userObject) {
		this.userObject = userObject;
	}
	
	/** 
	 * Returns String for Ajax Journal Preview.
	 * @param String Journal-Searchword s
	 * @return String Journals,that fit on saerchword
	 */
	public String getJournalPreview(String s){
		String myReturn="";
		JDBCBean dbCon= new JDBCBean();
		
		SQLResults res = dbCon.getResultSet("select distinct(journal) j  from literatur where journal like \"%"+s+"%\" limit 10");
		
		
		for(int i=0;i<res.getRowCount();i++){
			String result=res.getString(i,"j");
			myReturn+="<span onClick=\"document.forms.newMedium.publisher.value='"+result+"';document.getElementById('LSShadow').innerHTML='';document.getElementById('LSResult').style.visibility='hidden'\">"+result+"</span><br />";
			
		
		}
		return myReturn;
	}
	
	/** 
	 * Checks, if record with given ID ist currently in Wallet
	 * @param  id from record
	 * @return String containing an image showing an html checkbox that is clicked or not  
	 */
	public String checkWalletId(int id) {
		
		Calendar rightNow = Calendar.getInstance();
		int time=rightNow.get(Calendar.MINUTE)+rightNow.get(Calendar.SECOND)+rightNow.get(Calendar.MILLISECOND);
		String myLinkBegin="<a href=\"index.jsp?content="+this.getView()+"&amp;toggle="+id+"&amp;time="+time+"#record"+id+"\">";
		String myLinkEnd="</a>";
		if(this.wallet.contains(new Integer(id))){
			
			return myLinkBegin+"<img src=\"images/inWallet.png\" alt=\"Toggle Wallet\" title=\"Toggle Wallet\" border=\"0\" />"+myLinkEnd;
		}else{
			
			return myLinkBegin+"<img src=\"images/notInWallet.png\" alt=\"Toggle Wallet\" title=\"Toggle Wallet\" border=\"0\" />"+myLinkEnd;
		}
		
		
	}
	
	/**
	 * Removes record with given ID from wallet
	 * @param id from record
	 */
	public void removeFromWallet(int id) {
		this.getWallet().remove(new Integer(id));
	}
	
	/**
	 * adds record with given id to wallet
	 * @param id from record
	 */
	public void addToWallet(int id) {
		if(!this.wallet.contains(new Integer(id)))
			this.wallet.add(new Integer(id));
	}
	
	/**
	 * returns true, if record with given id is in wallet
	 * @param id from record
	 * @return true or false 
	 */
	public boolean isInWallet(int id) {
		return this.getWallet().contains(new Integer(id));
	}
	
	/**
	 * Returns size of wallet. 
	 * @return size of wallet
	 */
	public int walletSize() {
		return this.getWallet().size();
	}
	
	/**
	 * Removes record with given id from wallet if it is in the wallet. If not, the record is added to wallet
	 * @param id from record
	 */
	public void toggleWallet(int id){
		//Object myId=new Integer(id);
		
		
		if(this.isInWallet(id))
			this.removeFromWallet(id);
		else
			this.addToWallet(id);
		try{
			
			if(this.getView().equals("wallet")){
				this.getWalletMedia();
				this.getMedia();
			}else{
				this.getMedia();
			}
		}catch(Exception e){}
		
	}
	
	/**
	 * Removes record with give id from wallet if it is in the wallet. If not, the record is added to wallet
	 * @param id as String from record
	 * 
	 */
	public void toggleWalletString(String myId){
		int id;
		try{
			id=Integer.parseInt(myId);
			this.toggleWallet(id);
		}catch(Exception e){
			
		}
		
		
	}
	
	public Vector getWallet() {
		return this.wallet;
	}
	
	public void setWallet(Vector wallet) {
		this.wallet = wallet;
	}
	
	/**
	 * Empties the wallet if parameter equals "yes"
	 * @param what should be yes
	 */
	public void emptyWallet(String what){
		if(what==null)
			return;
		
		if(what.equals("yes")){
			
			this.getWallet().clear();
			
		}
	}
	
	public String getView() {
		return view;
	}
	
	public void setView(String view) {
		this.view = view;
	}
	
	public int getAnzWalletResults() {
		return anzWalletResults;
	}
	
	public void setAnzWalletResults(int anzWalletResults) {
		this.anzWalletResults = anzWalletResults;
	}
	
	
	public String getSearchWordAuthor() {
		return searchWordAuthor;
	}
	
	public void setSearchWordAuthor(String searchWordAuthor) {
		if(searchWordAuthor!=null)
			this.searchWordAuthor = searchWordAuthor.trim();
	}
	
	public String getSearchWordTitle() {
		return searchWordTitle;
	}
	
	public void setSearchWordTitle(String searchWordTitle) {
		if(searchWordTitle!=null)
		this.searchWordTitle = filterFirst(searchWordTitle).trim();
	}
	
	public String getErrorMessage() {
		return errorMessage;
	}
	
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	
	public String getSearchMessage() {
		return searchMessage;
	}
	
	public void setSearchMessage(String searchMessage) {
		this.searchMessage = searchMessage;
	}
	
	public void resetSearch(){
		
		this.setSearchResults("");
		this.setAnzSearchResults(0);
		this.setSearchMessage("");
		this.setSearchWordAuthor("");
		this.setSearchWordTitle("");
		this.setSearchWordSignatur("");
		this.setSearchWordEditor("");
		this.setSearchWordTitle2("");
		this.setSearchWordInstitute("");
		this.setSearchWordInventorynumber("");
		this.setSearchWordPublisher("");
		this.setSearchWordJournal("");
		this.setSearchWordYear("");
		this.setSearchWordMinYear("");
		this.setSearchWordMaxYear("");
		this.setSearchWordISBN("");
		this.setSearchWordISSN("");
		this.setSearchWordShelf("");
		
		this.setSearchWideTitle("");
		this.setSearchWideTitle2("");
		this.setSearchWideAuthor("");
		this.setSearchWideSignatur("");
		this.setSearchWideEditor("");
		this.setSearchWideInstitute("");
		this.setSearchWideInventorynumber("");
		this.setSearchWidePublisher("");
		this.setSearchWideJournal("");
		this.setSearchWideYear("");
		this.setSearchWideMaxYear("");
		this.setSearchWideMinYear("");
		this.setSearchWideISBN("");
		this.setSearchWideISSN("");
		this.setSearchWideShelf("");
		this.setCheckboxArticle("checked=\"checked\"");
		this.setCheckboxBook("checked=\"checked\"");
		this.setCheckboxGreylit("checked=\"checked\"");
		
		this.setStartwert(0);
		this.setOrderDirection(0);
		this.newSearchWord=true;
		
		this.setSearchWord("");
		
		this.objects.clear();
		
	}
	
	/**
	 * Returns the table Header from a Search only if there are any results
	 * @return
	 */
	public String getTableHeader(){
		String header="";
		header+="<tr >";
		header+="<th>No.</th>";
		header+="<th></th>";
		header+="<th><a href=\"index.jsp?content=search&amp;orderBy=litart&amp;orderDirection="+this.getOppositeOrderDirection()+"\">"+this.getOrderDirectionIcon("litart")+" "+this.getLangObject().getTextFor("search.Type")+"</a></th>";
		header+="<th><a href=\"index.jsp?content=search&amp;orderBy=author&amp;orderDirection="+this.getOppositeOrderDirection()+"\">"+this.getOrderDirectionIcon("author")+" "+this.getLangObject().getTextFor("search.Author")+"</a></th>";
		header+="<th><a href=\"index.jsp?content=search&amp;orderBy=title1&amp;orderDirection="+this.getOppositeOrderDirection()+"\">"+this.getOrderDirectionIcon("title1")+" "+this.getLangObject().getTextFor("search.Title")+"</a></th>";
		header+="<th style=\"width:50px;\"><a href=\"index.jsp?content=search&amp;orderBy=year&amp;orderDirection="+this.getOppositeOrderDirection()+"\">"+this.getOrderDirectionIcon("year")+" "+this.getLangObject().getTextFor("search.Year")+"</a></th>";
		header+="</tr>";
		if(this.getAnzSearchResults()>0)
			return header;
		
		return "";
	}


	public boolean isPrecise() {
		return precise;
	}


	public void setPrecise(boolean precise) {
		this.precise = precise;
	}
	
	/**
	 * Converts string retrieved from database in an array. Used only from authors 
	 * @param x (eg. Array with 3 authors "Christian Cleber","Alex Schaer","Marco Werner")
	 * @return 
	 */
	public String[] convertToArray(String x){
		
		String regex = "\",\"";
		String [] carved = Pattern.compile(regex).split(x);
		;
		carved[0]=carved[0].substring(1,carved[0].length());
		carved[carved.length-1]=carved[carved.length-1].substring(0,carved[carved.length-1].length()-1);
		return carved;
	}
	
	/**
	 * Returns all authors in author array as an String. All authors are seperated by semicolons
	 * @param authors
	 * @return
	 */
	public String showAuthorArray(String[] authors){
		String myString="";
		for(int i=0;i<authors.length;i++){
			if (authors[i].length() > 0) {
				myString+=authors[i]+"; ";
			}
		}
		if (myString.length() > 0) {
			myString=myString.substring(0,myString.length()-2);
		}
		return myString;
	}


	public String getSearchWordEditor() {
		return searchWordEditor;
	}


	public void setSearchWordEditor(String searchWordEditor) {
		if(searchWordEditor!=null)
		this.searchWordEditor = searchWordEditor.trim();
	}


	public String getSearchWordInstitute() {
		return searchWordInstitute;
	}


	public void setSearchWordInstitute(String searchWordInstitute) {
		if(searchWordInstitute!=null)
		this.searchWordInstitute = searchWordInstitute.trim();
	}

	public String getSearchWordInventorynumber() {
		return searchWordInventorynumber;
	}


	public void setSearchWordInventorynumber(String x) {
		if(x!=null)
		this.searchWordInventorynumber = x.trim();
	}
	
	public void setSearchWordShelf(String searchWordShelf) {
		if (searchWordShelf != null)
			this.searchWordShelf = searchWordShelf.trim();
	}
	
	public String getSearchWordShelf() {
		return this.searchWordShelf;
	}
	
	public void setSearchWordISBN(String searchWordISBN) {
		if (searchWordISBN != null)
			this.searchWordISBN = searchWordISBN.trim();
	}
	
	public String getSearchWordISBN() {
		return this.searchWordISBN;
	}
	
	public void setSearchWordISSN(String searchWordISSN) {
		if (searchWordISSN != null)
			this.searchWordISSN = searchWordISSN.trim();
	}
	
	public String getSearchWordISSN() {
		return this.searchWordISSN;
	}

	public String getSearchWordJournal() {
		return searchWordJournal;
	}


	public void setSearchWordJournal(String searchWordJournal) {
		if(searchWordJournal!=null)
		this.searchWordJournal = searchWordJournal.trim();
	}

	public String getSearchWordPublisher() {
		return searchWordPublisher;
	}

	public void setSearchWordPublisher(String searchWordPublisher) {
		if(searchWordPublisher!=null)
		this.searchWordPublisher = searchWordPublisher.trim();
	}

	public String getSearchWordSignatur() {
		return searchWordSignatur;
	}

	public void setSearchWordSignatur(String searchWordSignatur) {
		if(searchWordSignatur!=null)
		this.searchWordSignatur = searchWordSignatur.trim();
	}

	public String getSearchWordTitle2() {
		return searchWordTitle2;
	}

	public void setSearchWordTitle2(String searchWordTitle2) {
		if(searchWordTitle2!=null)
		this.searchWordTitle2 = searchWordTitle2.trim();
	}

	public String getSearchWordYear() {
		return searchWordYear;
	}

	public void setSearchWordYear(String searchWordYear) {
		if(searchWordYear!=null)
			this.searchWordYear = searchWordYear.trim();
	}

	public String getSearchWideAuthor() {
		return searchWideAuthor;
	}

	public void setSearchWideAuthor(String searchWideAuthor) {
		this.searchWideAuthor = searchWideAuthor;
	}

	public String getSearchWideEditor() {
		return searchWideEditor;
	}

	public void setSearchWideEditor(String searchWideEditor) {
		this.searchWideEditor = searchWideEditor;
	}

	public String getSearchWideInstitute() {
		return searchWideInstitute;
	}
	
	public String getSearchWideInventorynumber() {
		return searchWideInventorynumber;
	}
	
	public String getSearchWideShelf() {
		return this.searchWideShelf;
	}
	
	public String getSearchWideISBN() {
		return this.searchWideISBN;
	}
	
	public String getSearchWideISSN() {
		return this.searchWideISSN;
	}

	public void setSearchWideInstitute(String searchWideInstitute) {
		this.searchWideInstitute = searchWideInstitute;
	}
	
	public void setSearchWideInventorynumber(String searchWideInventory) {
		this.searchWideInventorynumber= searchWideInventory;
	}
	
	public void setSearchWideShelf(String searchWideShelf) {
		this.searchWideShelf = searchWideShelf;
	}
	
	public void setSearchWideISBN(String searchWideISBN) {
		this.searchWideISBN = searchWideISBN;
	}
	
	public void setSearchWideISSN(String searchWideISSN) {
		this.searchWideISSN = searchWideISSN;
	}

	public String getSearchWideJournal() {
		return searchWideJournal;
	}

	public void setSearchWideJournal(String searchWideJournal) {
		this.searchWideJournal = searchWideJournal;
	}

	public String getSearchWidePublisher() {
		return searchWidePublisher;
	}

	public void setSearchWidePublisher(String searchWidePublisher) {
		this.searchWidePublisher = searchWidePublisher;
	}

	public String getSearchWideSignatur() {
		return searchWideSignatur;
	}

	public void setSearchWideSignatur(String searchWideSignatur) {
		this.searchWideSignatur = searchWideSignatur;
	}
	
	public String getSearchWideTitle() {
		return searchWideTitle;
	}
	
	public void setSearchWideTitle(String searchWideTitle) {
		this.searchWideTitle = searchWideTitle;
	}
	
	public String getSearchWideTitle2() {
		return searchWideTitle2;
	}
	
	public void setSearchWideTitle2(String searchWideTitle2) {
		this.searchWideTitle2 = searchWideTitle2;
	}
	
	public String getSearchWideYear() {
		return searchWideYear;
	}
	
	public void setSearchWideYear(String searchWideYear) {
		this.searchWideYear = searchWideYear;
	}
	
	public String getSearchWideMaxYear() {
		return searchWideMaxYear;
	}
	
	public void setSearchWideMaxYear(String searchWideMaxYear) {
		this.searchWideMaxYear = searchWideMaxYear;
	}

	public String getSearchWideMinYear() {
		return searchWideMinYear;
	}

	public void setSearchWideMinYear(String searchWideMinYear) {
		this.searchWideMinYear = searchWideMinYear;
	}

	public String getSearchWordMaxYear() {
		return searchWordMaxYear;
	}

	public void setSearchWordMaxYear(String searchWordMaxYear) {
		if(searchWordMaxYear!=null)
		this.searchWordMaxYear = searchWordMaxYear;
	}

	public String getSearchWordMinYear() {
		return searchWordMinYear;
	}

	public void setSearchWordMinYear(String searchWordMinYear) {
		if(searchWordMinYear!=null)
		this.searchWordMinYear = searchWordMinYear;
	}
	
	public void setCheckboxArticle(String checkboxArticle) {
		if (checkboxArticle!=null && !checkboxArticle.equals("")) {
			this.checkboxArticle = "checked=\"checked\"";
		}
		else {
			this.checkboxArticle = "";
		}
	}
	
	public void setCheckboxBook(String checkboxBook) {
		if(checkboxBook!=null && !checkboxBook.equals("")) {
			this.checkboxBook = "checked=\"checked\"";
		}
		else {
			this.checkboxBook = "";
		}
	}
	
	public void setCheckboxGreylit(String checkboxGreylit) {
		if(checkboxGreylit!=null && !checkboxGreylit.equals("")) {
			this.checkboxGreylit = "checked=\"checked\"";
		}
		else {
			this.checkboxGreylit = "";
		}
	}
	
	/**
	 * Returns String "selected" if search for authors is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideAuthorHtml() {
		
		if(this.getSearchWideAuthor().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for editor is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideEditorHtml() {
		if(this.getSearchWideEditor().equals("no"))
			return "selected";
		else
			return "";			
	}
	
	/**
	 * Returns String "selected" if search for institute is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideInstituteHtml() {
		if(this.getSearchWideInstitute().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for inventorynumber is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideInventorynumberHtml() {
		if(this.getSearchWideInventorynumber().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for shelf is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideShelfHtml() {
		if(this.getSearchWideShelf().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for ISBN is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideISBNHtml() {
		if(this.getSearchWideISBN().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for ISSN is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideISSNHtml() {
		if(this.getSearchWideISSN().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for journal is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideJournalHtml() {
		if(this.getSearchWideJournal().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for publisher is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWidePublisherHtml() {
		if(this.getSearchWidePublisher().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for signatur is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideSignaturHtml() {
		if(this.getSearchWideSignatur().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for title1 is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideTitleHtml() {
		if(this.getSearchWideTitle().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for title2 is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideTitle2Html() {
		if(this.getSearchWideTitle2().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for year is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideYearHtml() {
		if(this.getSearchWideYear().equals("no"))
			return "selected";
		else
			return "";
	}
	
	/**
	 * Returns String "selected" if search for max year is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideMaxYearHtml() {
		if(this.getSearchWideMaxYear().equals("no"))
			return "selected";
		else
			return "";
	}

	/**
	 * Returns String "selected" if search for min year is wider. Returns an empty String, if not.
	 * @return
	 */
	public String getSearchWideMinYearHtml() {
		if(this.getSearchWideMinYear().equals("no"))
			return "selected";
		else
			return "";
	}

	public String getSearchWordMaxYearHtml() {
		if(this.getSearchWordMaxYear().equals("no"))
			return "selected";
		else
			return "";
	}

	public String getSearchWordMinYearHtml() {
		if(this.getSearchWordMinYear().equals("no"))
			return "selected";
		else
			return "";
	}

	public String getCheckboxArticle() {
		return this.checkboxArticle;
	}

	public String getCheckboxBook() {
		return this.checkboxBook;
	}
	
	public String getCheckboxGreylit() {
		return this.checkboxGreylit;
	}
	
	public SettingsBean getSettingsObject() {
		return settingsObject;
	}

	public void setSettingsObject(SettingsBean settingsobject) {
		this.settingsObject = settingsobject;
	}
	/*
	 * Replace a Substring in a String with another given substring
	 */
	public static String replaceAll(String source, String search,
			String replace) {
		if(search.equals(replace)) {
			return source; //kann ja sein, dass wir nichts tun m�ssen
		}
		
		StringBuffer result = new StringBuffer();
		int len = search.length();
		if(len == 0) {
			return source; //verhindert Endlosschleife bei search.equals("");
		}
		
		int pos = 0; //position
		int nPos;    //next position
		do {
			nPos = source.indexOf(search, pos);
			if(nPos != -1) { //gefunden
				result.append(source.substring(pos, nPos));
				result.append(replace);
				pos = nPos+len;
			} else { //nicht gefunden
				result.append(source.substring(pos)); //letzter abschnitt
			}
		} while(nPos!= -1);
		
		return result.toString();
	}
	
	public String[][] getJournalList() throws Exception {
		JDBCBean dbCon = new JDBCBean();
		String myQuery="select * from journals order by name asc";
		SQLResults res = dbCon.getResultSet(myQuery);
		String[][] journalList = new String[res.getRowCount()][3];
		for (int i=0; i<res.getRowCount(); i++) {
			journalList[i][0] = res.getString(i,1);
			journalList[i][1] = res.getString(i,3);
			journalList[i][2] = res.getString(i,4);
		}
		return journalList;
	}

	public List<ObjectFields> getObjects() {
		return objects;
	}

	public void setObjects(List<ObjectFields> objects) {
		this.objects = objects;
	}
}